package com.yang.springcloud.controller;

import com.yang.springcloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author yds
 * @program springcloud
 * @description 用于消费请求
 * @create 2020-09-17 16:32
 **/
@RestController
@RequestMapping("/consumer")
public class DeptConsumerController {

    //理解消费者 不应该用service
    //(url,实体:mapper,Class<T> responseType)
    @Autowired
    private RestTemplate restTemplate;//提供多种便捷访问远程http服务的方法

    //private static final  String REST_URL="http://localhost:8001";
    private static final  String REST_URL="http://SPRINGCLOUD-PROVIDER-DEPT";
    @RequestMapping("/dept/get/{id}")
    public Dept get(@PathVariable("id") Long id){
        return restTemplate.getForObject(REST_URL+"/dept/query/"+id,Dept.class);
    }
    @RequestMapping("/dept/list")
    public List<Dept> list(){
        return restTemplate.getForObject(REST_URL+"/dept/list",List.class);
    }
    @RequestMapping("/dept/add")
    public Boolean add(Dept dept){
        return restTemplate.postForObject(REST_URL+"/dept/add",dept,Boolean.class);
    }



}
